#pragma once
#include <d3d11.h>
#include "VertexFormats.h"
#include "IGrahpicsResource.h"

class VertexBuffer : public IGraphicsResource
{
	ID3D11Buffer* vertexBuffer;
	ID3D11Buffer* indexBuffer;

	void* vertexData = nullptr;
	unsigned int* indexData = nullptr;

	ID3D11InputLayout* inputLayout;

	unsigned int vertex_count;
	unsigned int index_count;
	unsigned int vertex_stride;
	unsigned int struct_size;


	// indicates this vertex buffer is dynamic, and can be changed after being created
	bool dynamic = false;

	D3D11_PRIMITIVE_TOPOLOGY topology = D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST;

public:
	VertexBuffer(void* vertexBuffer, unsigned int* index_buffer, unsigned int vertexCount, unsigned int indexCount, VertexFormats::Vertex_Type type, bool dynamic = false);
	~VertexBuffer(void);

	/////////////////////////<Accessors>///////////////////////////////////////////////////

	ID3D11Buffer* getVertexBuffer(void) const { return vertexBuffer; }
	ID3D11Buffer* getIndexBuffer(void) const { return indexBuffer; }

	unsigned int getVertexCount(void) const { return vertex_count; }
	unsigned int getIndexCount(void) const { return index_count; }
	unsigned int getVertexStride(void) const { return vertex_stride; }

	ID3D11InputLayout* getInputLayout(void) const { return inputLayout; }

	D3D11_PRIMITIVE_TOPOLOGY getTopology(void) const { return topology; }

	/////////////////////////<Mutators>///////////////////////////////////////////////////

	void setTopology(D3D11_PRIMITIVE_TOPOLOGY value) { topology = value; }

	/////////////////////<Interface>//////////////////////////////////////////


	// copies data in video memory to CPU memory
	virtual void getData(void* data, unsigned int pixelStride) override;
	// copies resource data in CPU memory to video memory
	virtual void setData(void* data, unsigned int pixelStride) override;
	// gets the data on the index buffer
	void getIndexData(unsigned int** data);

	// gets the d3d11 object that represents the resource
	virtual ID3D11Resource* getResource(void) const override { return vertexBuffer; }
	// gets shader resource view for this resource
	virtual ID3D11ShaderResourceView* getSrv(void) const override { return nullptr; }

	// gets the d3d11 descriptor for this object and copies it onto 'desc'
	virtual void getDesc(void* desc) override { vertexBuffer->GetDesc((D3D11_BUFFER_DESC*)desc); }
};